package main

import (
	"fmt"
	"html/template"
	"net/http"
	"test/gee/day06/gee"
	"time"
)

type student struct {
	Name string
	Age  int8
}

func formatAsDate(t time.Time) string {
	year, month, day := t.Date()
	return fmt.Sprintf("%d-%02d-%02d", year, month, day)
}

func main() {

	r := gee.New()
	r.Use(gee.Logger())

	r.SetFuncMap(template.FuncMap{
		"formatAsDate": formatAsDate,
	})
	//D:/code/me/go/git/src/study-go/gee/day06/
	r.LoadHTMLGlob("src/study-go/gee/day06/templates/*")
	r.Static("/assets", "src/study-go/gee/day06/static")

	stu1 := &student{Name: "gee", Age: 20}
	stu2 := &student{Name: "jakc", Age: 22}

	r.GET("/", func(c *gee.Context) {
		c.HTML(http.StatusOK, "css.tmpl", nil)
	})

	r.GET("/students", func(c *gee.Context) {
		c.HTML(http.StatusOK, "arr.tmpl", gee.H{
			"title":  "gee",
			"stuArr": [2]*student{stu1, stu2},
		})
	})

	r.GET("/date", func(c *gee.Context) {
		c.HTML(http.StatusOK, "custom_func.tmpl", gee.H{
			"title": "gee",
			"now":   time.Date(2020, 3, 30, 17, 27, 28, 0, time.UTC),
		})
	})

	r.Run(":8080")
}
